var GenerateAssetPlugin = require('generate-asset-webpack-plugin');
const [mapCfg, mockCfg, communityCfg] = [require('./map.json'), require('./mockConfig.json'), require('./community.json')].map(el => function (compilation) {
  return JSON.stringify(el);
})

module.exports = {
  publicPath: process.env.BASE_URL || './',
  devServer: {
    disableHostCheck: true, // 关闭host检查
    host: '0.0.0.0',
    port: 9926, // 我只开启了阿里云的9900~9999端口，所以从8080改成9977
    //   sockHost: '8.131.75.111', // webpack的hot module replacement需要
    //   public: '8.131.75.111', // 同上
    proxy: {
      '/api/': {
        target: 'https://xxxxx',
        // 如果要代理 websockets
        ws: false,
        // 将主机标头的原点更改为目标URL
        changeOrigin: true,
        pathRewrite: {
          "^/api": ""
        }
      }
    }
  },
  configureWebpack: {
    // webpack plugins
    plugins: [
      ...([mapCfg, mockCfg, communityCfg].map((el, key) => new GenerateAssetPlugin({
        filename: ['map.json', 'mockConfig.json', 'community.json'][key],
        fn: (compilation, cb) => {
          cb(null, el(compilation));
        },
        extraFiles: []
      })))
    ]
  },
  css: {
    loaderOptions: {
      scss: {
        additionalData: `@import "@/assets/scss/_variable.scss";`
      }

    }
  },
  // chainWebpack: config => {
  //     config.module
  //         .rule('scss')
  //         .test(/\.scss$/)
  //         .oneOf('vue')
  //         .use('px2rem-loader')
  //         .loader('px2rem-loader')
  //         .before('postcss-loader')
  //         .options({
  //             remUni: 192,
  //             remPrecision: 8
  //         })
  //         .end()
  // }
  productionSourceMap: false,
}